import RichEditor from './index.vue'

// 扩展 EmapForm 自定义组件
export default () => {
  let typeName = RichEditor.xtype
  let compName = typeName
  let refName = compName.replace(/-(\w)/g, (a, b) => b.toLowerCase()) // ref名字必须为小写

  // eslint-disable-next-line no-undef
  WIS_EMAP_INPUT.extend({
    xtype: RichEditor.xtype,
    init: function (ele) {
      const name = ele.data('name')

      this.vm = new Vue({
        template: `<${compName} name="${name}" ref="${refName}"></${compName}>`,
        components: {
          [compName]: RichEditor
        },
      })

      this.vm.$mount(ele.get(0))
    },
    setValue: function (ele, name, val) {
      return this.vm.$refs[refName].setValue(val)
    },
    getValue: function () {
      return this.vm.$refs[refName].getValue()
    },
    setDisplay (elem, name, val) {
      elem.html(val && val[name] || '')
      elem.css('height', 'auto')
    }
  })
}
